<%--
  Created by IntelliJ IDEA.
  User: SuZePing
  Date: 2021/1/16
  Time: 23:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<%@include file="/WEB-INF/include/include-head.jsp"%>
	<link rel="stylesheet" href="static/css/pagination.css">
	<script src="static/jquery/jquery.pagination.js"></script>
	<script type="text/javascript">
		$(function () {
		    // Pagination分页初始化
            initPagination();

			// 提示是否删除
			$(".btn.btn-danger.btn-xs").click(function () {
				var nameText = "您确定要删除用户[" + $(this).parent().siblings().eq(2).text() + "]吗？";
				return confirm(nameText);
			});

        });

		// 初始化分页
		function initPagination() {
			// 获取总记录数
			var totalRecord = ${requestScope.pageInfo.total};
			// 声明pagination属性
			var properties = {
			    // 边缘页数
			    num_edge_entries: 3,
				// 主体页数
				num_display_entries: 5,
				// 回调函数
				callback: paginationCallBack,
				// 每页显示的条数
				items_per_page: ${requestScope.pageInfo.pageSize},
				// 当前显示的页面
				current_page: ${requestScope.pageInfo.pageNum - 1},
				// 上一页与下一页按钮上显示的文本
				prev_text: "上一页",
				next_text: "下一页"
			};
			// 生成页码导航条
			$("#Pagination").pagination(totalRecord,properties);
        }
        
        // pagination回调函数 [跳转页面]
		function paginationCallBack(pageIndex, jQuery) {
			var pageNum = pageIndex + 1;
			window.location.href = "admin/get/page.html?pageNum=" + pageNum + "&keyword=${param.keyword}";
            return false;
        }
        
	</script>
</head>
<body>
<%@ include file="/WEB-INF/include/include-nav.jsp"%>
<div class="container-fluid">
	<div class="row">
<%@include file="/WEB-INF/include/include-sidebar.jsp"%>
		<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 id="title" class="panel-title"><i class="glyphicon glyphicon-th"></i> 用户列表</h3>
				</div>
				<div class="panel-body">
					<form action="admin/get/page.html" method="get" class="form-inline" role="form" style="float:left;">
						<div class="form-group has-feedback">
							<div class="input-group">
								<div class="input-group-addon">查询条件</div>
								<input id="keyword" name="keyword" class="form-control has-success"
									   type="text" placeholder="请输入查询条件" value="${param.keyword}">
							</div>
						</div>
						<button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询</button>
					</form>
					<a href="admin/to/add/page.html" class="btn btn-primary" style="float:right;"><i class="glyphicon glyphicon-plus"></i> 新增</a>
					<br>
					<hr style="clear:both;">
					<div class="table-responsive">
						<table class="table  table-bordered">
							<thead>
							<tr>
								<th width="30">#</th>
								<th>账号</th>
								<th>名称</th>
								<th>邮箱地址</th>
								<th width="100">操作</th>
							</tr>
							</thead>
							<tbody id="tbody">
							<%-- 没有查到数据 --%>
							<c:if test="${empty requestScope.pageInfo.list}">
								<tr>
									<td colspan="6" align="center">没有查到数据!</td>
								</tr>
							</c:if>
							<%-- 查到数据 --%>
							<c:if test="${not empty requestScope.pageInfo.list}">
								<c:forEach items="${requestScope.pageInfo.list}" var="admin" varStatus="status">
									<tr>
										<td>${(requestScope.pageInfo.pageNum - 1) * requestScope.pageInfo.pageSize + status.count}</td>
										<td>${admin.account}</td>
										<td>${admin.name}</td>
										<td>${admin.email}</td>
										<td>
											<a href="assign/to/adminRole/page.html?adminId=${admin.userId}&pageNum=${requestScope.pageInfo.pageNum}&keyword=${param.keyword}" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></a>
											<a href="admin/to/edit/page.html?adminId=${admin.userId}&pageNum=${requestScope.pageInfo.pageNum}&keyword=${param.keyword}" class="btn btn-primary btn-xs"><i class=" glyphicon glyphicon-pencil"></i></a>
											<a href="admin/remove/${admin.userId}/${requestScope.pageInfo.pageNum}/${param.keyword}.html" adminId="${admin.userId}" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></a>
										</td>
									</tr>
								</c:forEach>
							</c:if>
							</tbody>
							<tfoot>
							<tr>
								<td colspan="6" align="center">
									<div id="Pagination" class="pagination"><%-- 显示Pagination分页 --%></div>
								</td>
							</tr>
							</tfoot>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

</body>
</html>

